package com.android.job.service.request;

import java.util.ArrayList;

import org.apache.http.message.BasicNameValuePair;

import android.os.Handler;
import android.util.Log;

import com.android.job.fusion.FusionCode;
import com.android.job.model.LoginInfo;
import com.android.job.model.PostInfo;
import com.android.job.service.ConnectionTask;
import com.android.job.service.JSONRequest;
import com.android.job.util.CommonUtil;
import com.android.job.util.json.JSONException;
import com.android.job.util.json.JSONObject;

/**
 * 登录请求
 * 
 * @author
 * 
 */
public class RegisterRequest extends JSONRequest
{
	private String userPassword;
	private String name;
	private String gender;
	private String identity;
	private String mobileNumber;
	private String region;
	private String type;
	private String nature;

	private String degree;
	private String categories;
	private String political;
	private String salary;
	private String census;
	private String marital;
	private String mailingAddress;
	private String homeAddress;
	private String qq;
	private String email;
	private String msn;
	private String recentType;
	private String recentYear;

	public RegisterRequest(Handler handler, String httpUrl)
	{
		super(handler, httpUrl);
		setHttpType(ConnectionTask.POST);
	}

	public void setValues( String userPassword, String name,
			String gender, String identity, String mobileNumber,
			String degree, String categories, String political,
			String salary, String region, String type, String nature,
			String census, String marital, String mailingAddress,  String homeAddress, String qq,
			String email, String msn, String recentType, String recentYear)
	{
		this.userPassword = userPassword;
		this.name = name;
		this.gender = gender;
		this.identity = identity;
		this.mobileNumber = mobileNumber;
		this.region = region;
		this.type = type;
		this.nature = nature;

		this.degree = degree;
		this.categories = categories;
		this.political = political;
		this.salary = salary;
		this.census = census;
		this.marital = marital;
		this.mailingAddress = mailingAddress;
		this.homeAddress = homeAddress;
		this.qq = qq;
		this.email = email;
		this.msn = msn;
		this.recentType = recentType;
		this.recentYear = recentYear;

	}

	@Override
	protected boolean parseJSONResponse(JSONObject json)
	{
		Log.i("RegisterRequest","===response===json======"+json.toString());
		if (!json.isNull("jsonData"))
		{
			JSONObject jsonObject;
			try
			{
				jsonObject = json.getJSONObject("jsonData");
				LoginInfo info = new LoginInfo();
				info.userType = "0";
				if (!jsonObject.isNull("success"))
				{
					info.success = jsonObject.getString("success");
				}
				
				if (!jsonObject.isNull("userId"))
				{
					info.userId = jsonObject.getString("userId");
				}
				CommonUtil.sendMessage(handler, FusionCode.RETURN_JSONOBJECT,
						info);
			}
			catch (JSONException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			
			
		}

		return true;
	}

	@Override
	protected void appendMainBody()
	{
		this.paramsters = new ArrayList();
		JSONObject userJson;
		try
		{
			jsonObject = new JSONObject();
			userJson = new JSONObject();

			userJson.put("passWord", userPassword);
			userJson.put("name", name);
			userJson.put("gender", gender);
			userJson.put("identity", identity);
			userJson.put("mobileNumber", mobileNumber);
			userJson.put("region", region);
			userJson.put("type", type);
			userJson.put("nature", nature);
			userJson.put("degree", degree);
			userJson.put("categories", categories);
			userJson.put("political", political);
			userJson.put("salary", salary);
			userJson.put("census", census);
			userJson.put("marital", marital);
			userJson.put("mailingAddress", mailingAddress);
			userJson.put("homeAddress", homeAddress);
			userJson.put("qq", qq);
			userJson.put("email", email);
			userJson.put("msn", msn);
			userJson.put("recentType", recentType);
			userJson.put("recentYear", recentYear);

			jsonObject.put("requestType", "registeredAccount");
			jsonObject.put("jsonData", userJson);
			paramsters.add(new BasicNameValuePair("jsonData", jsonObject.toString()));
			Log.i("LoginRequest", "===RejisterRequest====="+jsonObject.toString());
		} catch (JSONException e)
		{
			e.printStackTrace();
		}
	}

}
